package com.birboot.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientHandler  implements Runnable {
    private Socket socket;

    public ClientHandler(Socket socket) {
        this.socket = socket;
    }

    public void run(){
        try {
            InputStream is= socket.getInputStream();
            int d;
            char pre = 'a',cur='a';//pre代表上次读取的字符，cur代表这次读取的字符
            StringBuilder builder = new StringBuilder();//保存读取后的所有字符
            while ((d=is.read())!=-1) {
                cur = (char) d;//本次读取字符
                if (pre == 13 && cur == 10) {//判断是否为回车和换行
                    break;
                }
                builder.append(cur);//将本次读取的字符拼接
                pre = cur;//把本次读取的字符给到pre
            }
            String line = builder.toString().trim();
                System.out.print("请求行："+line);
                //请求相关信息
                String method ;
                String uri;
                String protocol;
                String[] a =line.split("\\s");
                method=a[0];
                uri=a[1];
                protocol=a[2];
            System.out.println("");
            System.out.println("method:"+method);
            System.out.println("uri:"+uri);
            System.out.println("protocol:"+protocol);
                
                
                
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
